<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <h2>todolist</h2>

    <input type="text" v-model="inputValue" />
    <button @click="add">提交</button>

    <h3>未完成</h3>
    <ul>
      <li v-for="item in unCheckedList" :key="item.name">
        <input type="checkbox" v-model="item.status"> - 
        {{ item.name }} - <button @click="remove(item)">删除</button>
      </li>
    </ul>

    <h3>已完成</h3>
    <ul>
      <li v-for="item in checkedList" :key="item.name">
        <input type="checkbox" v-model="item.status"> - 
        {{ item.name }} - <button @click="remove(item)">删除</button>
      </li>
    </ul>
  </div>

  <script src="../vue3.js"></script>
  <script>
    const {createApp} = Vue;

    createApp({
      data() {
        return {
          inputValue: "",
          list: [
            {
              name: "张三",
              status: false,
            },
            {
              name: "里斯",
              status: false,
            },
            {
              name: "王武",
              status: false,
            }
          ],
          // checkedList: []
        }
      },
      methods: {
        add() {
          if (this.inputValue && !this.list.includes(this.inputValue)) {
            this.list.push({name: this.inputValue, status: false});
            this.inputValue = "";
          }
        },
        remove(value) {
          this.list = this.list.filter(item => item.name !== value.name)
        }
      },
      computed: {
        checkedList() {
          return this.list.filter(item => item.status)
        },
        unCheckedList() {
          return this.list.filter(item => !item.status)
        }
      }
    }).mount("#app");
  </script>
</body>
</html>